//
//  ZYCProfileRootHeaderView.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/16.
//

#import "ZYCProfileRootHeaderView.h"
#import "ZYCProfileUserInfoView.h"
#import "ZYCUserInfoModel.h"
#import <UIImageView+WebCache.h>
#import "URLManager.h"

@interface ZYCProfileRootHeaderView ()
@property (nonatomic, strong) UIImageView *bgImageView;
@property (nonatomic, strong) UIView *greenView;
@property (nonatomic, strong) UIImageView *headerIconView;
@property (nonatomic, strong) ZYCProfileUserInfoView *userInfoView;
@end
@implementation ZYCProfileRootHeaderView

- (void)setModel:(ZYCUserInfoModel *)model{
    _model = model;
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/zd-system-service%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"sdfz_url"],model.customizePath]];
    [_headerIconView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"tx"]];
    _userInfoView.model = model;
}


- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.bgImageView];
        [self addSubview:self.userInfoView];
        [self addSubview:self.greenView];
        [self.greenView addSubview:self.headerIconView];
        [self.greenView bringSubviewToFront:self];
        [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
        [self.userInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.top.equalTo(self.headerIconView.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(250, 139));
        }];
        [self.greenView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.top.equalTo(self).offset(60);
            make.size.mas_equalTo(CGSizeMake(109, 109));
        }];
        
        [self.headerIconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self.greenView);
            make.size.mas_equalTo(CGSizeMake(109, 109));
        }];
    }
    return self;
}

- (UIImageView *)bgImageView {
    if (!_bgImageView) {
        _bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"图层 1"]];
    }
    return _bgImageView;
}

- (UIView *)greenView {
    if (!_greenView) {
        _greenView = [[UIView alloc] init];
        _greenView.backgroundColor = HEX_RGB(@"#009B4C");
        _greenView.layer.cornerRadius = 109 / 2;
        _greenView.layer.masksToBounds = YES;
    }
    return _greenView;
}

- (UIImageView *)headerIconView {
    if (!_headerIconView) {
        _headerIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tx"]];
        _headerIconView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickTap:)];
        [_headerIconView addGestureRecognizer:tap];
    }
    return _headerIconView;
}

- (ZYCProfileUserInfoView *)userInfoView {
    if (!_userInfoView) {
        _userInfoView = [[ZYCProfileUserInfoView alloc] init];
    }
    return _userInfoView;
}

- (void)clickTap:(UIGestureRecognizer *)ges{
    if ([self.delegate respondsToSelector:@selector(profileRootHeaderViewDidClickHeader)]) {
        [self.delegate profileRootHeaderViewDidClickHeader];
    }
}
@end
